$(() => {
    $("img.lazyload").lazyload();
})
$(function () {
    let $recommended_goods_list_wrapper = $(".recommended_goods_list");
    let $recommended_nav = $(".recommended_nav ul");
    let $recommended_goods_list = $(".recommended_goods_list");
    let recommended_goods_list_options = {
        url: "../json/index_recommend_to_you.json"
    }
    $.ajax(recommended_goods_list_options)
        .then(function (res) {
            let data = res.data;
            let html = "";
            for (let attr in data) {

                html += ` <li>
                            <div class="recommend_goods_pic">
                                <img class="lazyload" data-original="${data[attr].img_url}" alt="">
                            </div>
                            <div class="recommend_goods_name">
                                ${data[attr].goods_name}
                            </div>
                                ${data[attr].label && data[attr].label2 ? `<div class="recommend_goods_tag">
                                <span>${data[attr].label}</span>
                                <span>${data[attr].label2}</span>
                            </div>` : `<div style="height: 20px;"></div>`}
                            
                            <div class="recommend_goods_price">
                                <div class="new_price">
                                    <i>￥</i>
                                    <span>${data[attr].new_price}</span>
                                </div>
                                <div class="old_price">
                                    <i>￥</i>
                                    <span>${data[attr].old_price}</span>
                                </div>
                            </div>
                        </li>`
            }
            $recommended_goods_list_wrapper.html(html);
            $("img.lazyload").lazyload();

            // console.log($(".recommend_goods_tag span").text());
            // if($(".recommend_goods_tag span").text()){
            //     console.log($(this));
            //     $(this).remove()
            // }


        })

    // 吸顶菜单
    $(window).scroll(function () {
        if ($("body,html").scrollTop() >= $recommended_goods_list.offset().top) {
            $recommended_nav.addClass("fixed_reco_nav")
        }
        if ($("body,html").scrollTop() < $recommended_goods_list.offset().top) {
            $recommended_nav.removeClass("fixed_reco_nav")
        }
    })

    // 吸顶菜单
    $(".recommended_nav ul li").click(function () {  
        $(this).addClass("active").siblings().removeClass("active");
    })


})